<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/6/21 0021
  Time: 12:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../base.jsp" %>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${basePath}/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${basePath}/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" method="post">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字</label>
                            <div class="layui-input-inline">
                                <input type="text" name="searchKey" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <%-- <div class="layui-inline">
                             <label class="layui-form-label">账号</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="account" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">用户城市</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="city" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">用户职业</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="classify" autocomplete="off" class="layui-input">
                             </div>
                         </div>--%>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">搜索选择框</label>
                            <div class="layui-input-inline">
                                <select name="modules" lay-verify="required" lay-search="">
                                    <option value="">直接选择或搜索选择</option>
                                    <option value="1">layer</option>
                                    <option value="2">form</option>
                                    <option value="3">layim</option>
                                    <option value="4">element</option>
                                    <option value="5">laytpl</option>
                                    <option value="6">upload</option>
                                    <option value="7">laydate</option>
                                    <option value="8">laypage</option>
                                    <option value="9">flow</option>
                                    <option value="10">util</option>
                                    <option value="11">code</option>
                                    <option value="12">tree</option>
                                    <option value="13">layedit</option>
                                    <option value="14">nav</option>
                                    <option value="15">tab</option>
                                    <option value="16">table</option>
                                    <option value="17">select</option>
                                    <option value="18">checkbox</option>
                                    <option value="19">switch</option>
                                    <option value="20">radio</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 发布公告 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <%--  <script type="text/html" id="currentTableBar">
              <a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert" lay-event="insert">录入成绩</a>
              <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
          </script>--%>

    </div>
</div>
<script src="${basePath}/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '${basePath}/ggao/list/fggao',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: '公告序号'},
                {field: 'title', title: '公告标题'},
                {field: 'teacherid',  title: '发布者'},
                {title: '审核状态', width: 400, align: "center",templet:function(d){
                        var html = '';
                        if(d.state==0){
                            html = '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" >待审核</a>';
                        }else if(d.state==1){
                            html = '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="1">审核通过</a>';
                        } else if(d.state==2){
                            html = '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="1">审核不通过</a>';
                        }
                        return html;
                    }},
                {title: '操作', width: 270, align: "center",templet:function(d){
                        var html = '';
                        if(d.teacherid=='${sessionScope.user.realname}'){
                            html =  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert" lay-event="see">查看公告内容</a>';
                            html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert" lay-event="edit">编辑公告</a>';
                            html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert" lay-event="cancle">撤回公告</a>';
                        }else{
                            html =  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert" lay-event="see">查看公告内容</a>';
                            html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit layui-btn-disabled" >编辑公告</a>';
                            html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs data-count-insert layui-btn-disabled">撤回公告</a>';
                        }
                        return html;
                    }}
            ]],
            limits: [2,5,10, 15, 20],
            limit: 5,
            page: true,
            skin: 'line',
            parseData: function(res){ //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                var result;
                if(this.page.curr){
                    result = res.data.slice(this.limit*(this.page.curr-1),this.limit*this.page.curr);
                }
                else{
                    result=res.data.slice(0,this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                };
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            /*layer.alert(result, {
                title: '最终的搜索信息'
            });*/

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchKey: data.field.searchKey
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '发布公告',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '${basePath}/ggao/addggao',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });


        //录入成绩
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'see') {

                var index = layer.open({
                    title: '查看公告内容',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '${basePath}/ggao/seeggao?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑公告',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '${basePath}/ggao/editggao?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            else if (obj.event === 'cancle') {
                layer.confirm('确定要撤回此公告吗？', function (index) {
                    $.ajax({
                        url:'${basePath}/ggao/cancleggao',
                        type:'get',
                        data:{'id':data.id},
                        dataType:'json',
                        success:function (res){
                            if(res.code===0){
                                layer.msg(res.msg,function(){
                                    //删除页面表格行元素
                                    obj.del();
                                    //关闭confirm弹窗
                                    layer.close(index);
                                })
                            }else{
                                layer.alert(res.msg);
                            }
                        }
                    })

                });
            }
        });

    });
</script>

</body>
</html>

